//package com.plian.system.service.yth.impl;
//
//import com.baomidou.dynamic.datasource.annotation.DS;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.plian.Tools.CollectionUtil;
//import com.plian.system.entity.yth.ProjectEvaluate;
//import com.plian.system.mapper.yth.ProjectEvaluateMapper;
//import com.plian.system.service.yth.IProjectEvaluateService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.time.LocalDate;
//import java.time.ZoneId;
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * @Description: TODO
// * @Author: Take-off
// * @Date: 2023/4/17 4:02 PM
// * @Param
// * @return
// * @Version: 1.0
// **/
//@Slf4j
//@Service
//@DS("slave_1")
//public class ProjectEvaluateServiceImpl extends ServiceImpl<ProjectEvaluateMapper,ProjectEvaluate> implements IProjectEvaluateService {
//
//    private final String YTH_DATASOURCE_TYPE = "3";
//
//
//    @Transactional(rollbackFor = Exception.class)
//    @DS("slave_1")
//    @Override
//    public List<InvestmentEvaluation> getAllProject(Date startTime,Date endTime){
//        List<InvestmentEvaluation> investmentEvaluations = new ArrayList<>();
//
//        List<ProjectEvaluate> allEvaluate = list(new LambdaQueryWrapper<ProjectEvaluate>().isNotNull(ProjectEvaluate::getReportOrgId)
//                .isNotNull(ProjectEvaluate::getReportTime)
//                .gt(Optional.ofNullable(startTime).isPresent(),ProjectEvaluate::getCreateTime,startTime)
//                .le(Optional.ofNullable(endTime).isPresent(),ProjectEvaluate::getCreateTime,endTime)
//        );
//        if (CollectionUtil.isNotEmpty(allEvaluate)){
//            investmentEvaluations = conversion(allEvaluate);
//        }
//        return investmentEvaluations;
//    }
//
//
//    /**
//     * @Description: //TODO entity 转换
//     * @Author: Take-off
//     * @Date: 4:38 PM 2023/4/17
//     * @Param: [projectEvaluates]
//     * @return: java.util.List<com.plian.system.entity.im.InvestmentEvaluation>
//     **/
//    private List<InvestmentEvaluation> conversion(List<ProjectEvaluate> projectEvaluates){
//        List<InvestmentEvaluation> investmentEvaluations = new ArrayList<>();
//
//        ZoneId zone = ZoneId.systemDefault();
//        //根据填报时间 和 填报组织 归集
//        Map<Long, List<ProjectEvaluate>> mapByOrg = projectEvaluates.stream().collect(Collectors.groupingBy(ProjectEvaluate::getReportOrgId));
//        for(Long orgId:mapByOrg.keySet()){
//            List<ProjectEvaluate> evaluateList = mapByOrg.get(orgId);
//            Map<LocalDate, List<ProjectEvaluate>> mapByTime = evaluateList.stream().collect(Collectors.groupingBy(ProjectEvaluate::getReportTime));
//            for (LocalDate date:mapByTime.keySet()){
//                InvestmentEvaluation investmentEvaluation = new InvestmentEvaluation();
//                List<InvestmentEvaluationDetail> details = new ArrayList<>();
//
//                List<ProjectEvaluate> evaluates = mapByTime.get(date);
//                ProjectEvaluate projectEvaluate = evaluates.get(0);
//                investmentEvaluation.setReportOrgId(projectEvaluate.getReportOrgId().toString());
//                investmentEvaluation.setReportTime( Date.from(date.atStartOfDay().atZone(zone).toInstant()) );
//                investmentEvaluation.setProjectNumber(evaluates.size());
//                for (ProjectEvaluate evaluate:evaluates){
//                    InvestmentEvaluationDetail detail = new InvestmentEvaluationDetail();
//                    detail.setProjectInfoId(evaluate.getProjectId());
//                    detail.setReturnRate(evaluate.getInvestActualBenefit());
//                    detail.setEvaluationOrg(evaluate.getEvaluateOrgName());
//                    detail.setAfterEvaluationTime(evaluate.getEvaluateCompleteTime());
//                    detail.setAttachIds(evaluate.getAttachIds());
//                    details.add(detail);
//                }
//                investmentEvaluation.setEvaluationDetails(details);
//                investmentEvaluation.setDataSource(YTH_DATASOURCE_TYPE);
//                investmentEvaluations.add(investmentEvaluation);
//            }
//        }
//        return investmentEvaluations;
//    }
//
//}
